import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'

Vue.config.productionTip = false


 import moment from 'moment'

 Vue.filter('format',function(datastr,patten ="YYYY-MM-DD HH:mm:ss"){
  return moment (datastr).format(patten)
 })

//头部
import { Header,Swipe, SwipeItem,Lazyload ,Field , Switch} from 'mint-ui';
import 'mint-ui/lib/style.css';
Vue.component(Header.name, Header); 

//登录表单
Vue.component(Field.name, Field);
//头部按钮
import { Button } from 'mint-ui';

Vue.component(Button.name, Button);

import './lib/mui/css/mui.css'

//字体样式引入
import './lib/mui/css/icons-extra.css'
//图片分享中的缩略图
import  Preview from 'vue-preview';

//轮播图
Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
//自主图片
Vue.use(Lazyload);
//缩略图
Vue.use(Preview);
//
Vue.component(Switch.name, Switch);

//router守护拦截部分
router.beforeEach((to, from, next) => {
  var mytoken = localStorage.getItem("mytoken");
  // console.log(to,2);
  // console.log(from,3);
  // console.log(router,567);

  if (mytoken) {
    if(to.path != "/login"){
      next();
    }else{
      next({
        path: "/myhome"//你的首页的路由名字我的是myhome,
      });
    }
  } else {
    if (to.path != "/login") {
      next({
        path: "/login"
      });
    } else {
      next();
    }
  }
})





new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
